﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using EnvDTE80;

namespace CSharpCodeAssistant
{
    partial class SelectOptionsForm : Form
    {
        CodeGenerator codeGenerator;
        internal SelectOptionsForm(CodeGenerator codeGenerator)
        {
            this.codeGenerator = codeGenerator;
            InitializeComponent();
            CenterToScreen();
            DisableNecessaryRadio();
        }

        internal SelectOptionsForm()
        {            
            InitializeComponent();
            CenterToScreen();
        }


        internal void DisableNecessaryRadio()
        {
            List<CodeVariable2> temp=codeGenerator.GetListOfVariables();
            if (temp == null || temp.Count == 0)
            {
                //that means no variables in the class so disable all property radio buttons.
                //because you can have empty constructor
                ReadOnlyPropertyRadioButton.Enabled = false;
                WriteOnlyPropertyRadioButton.Enabled = false;
                ReadWritePropertyRadioButton.Enabled = false;
            }

        }

        /// <summary>
        /// This property is a set/get the code generator instance.
        /// </summary>
        internal CodeGenerator CodeGen
        {
            set
            {
                codeGenerator = value;
            }
            get
            {
                return codeGenerator;
            }

        }

        /// <summary>
        /// This Method is used to close a windows form.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CancelButton_Click(object sender, EventArgs e)
        {
            this.Hide();
            this.Close();
            this.Dispose();                       
        }

        /// <summary>
        /// This Method is used to proceed with next screen where we can see the list of variables available for the class.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void NextButton_Click(object sender, EventArgs e)
        {
            ListOfOptionsForFirstWindow optionSelected=ListOfOptionsForFirstWindow.None;            
            if (ConstructorRadioButton.Checked)
            {
                optionSelected = ListOfOptionsForFirstWindow.Constructor;               
            }
            else if (ReadOnlyPropertyRadioButton.Checked)
            {
                optionSelected = ListOfOptionsForFirstWindow.ReadOnlyProperty;
            }
            else if (WriteOnlyPropertyRadioButton.Checked)
            {
                optionSelected = ListOfOptionsForFirstWindow.WriteOnlyProperty;
            }
            else if (ReadWritePropertyRadioButton.Checked)
            {
                optionSelected = ListOfOptionsForFirstWindow.ReadWriteProperty;
            }
            else
            {
                MessageBox.Show(Constant.MSG_NO_OPT_SELECTED_FIRST_WIN);
                return;
            }
            //navigate to next window.
            SelectMembersForm selectMembersForm = new SelectMembersForm(codeGenerator, optionSelected);
            this.Hide();
            this.Close();
            this.Dispose();
            selectMembersForm.ShowDialog();
        }
    }
}
